package cn.afactory.tygz.ui.base.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import cn.afactory.tygz.R;
import cn.afactory.tygz.ui.base.utils.StringUtils;

public class AppSettingItem extends RelativeLayout {
	private ImageView iconView;
	private TextView titleView;
	private TextView tv_summary;
	public AppSettingItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		
		init(context);
	}

	public AppSettingItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		init(context);
	}

	public AppSettingItem(Context context) {
		super(context);
		
		init(context);
	}

	private void init(Context context){
		LayoutInflater mLayoutInflater = LayoutInflater.from(context);
		View view = mLayoutInflater.inflate(R.layout.app_settings_item, null);
		
		LayoutParams rlp = new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		
		iconView = (ImageView)view.findViewById(R.id.icon);
		titleView = (TextView)view.findViewById(R.id.title);
		tv_summary = (TextView)view.findViewById(R.id.tv_summary);
		
		addView(view, rlp);
		
		setBackgroundResource(R.drawable.mine_menu_bg_selector);
	}

	public void setSummary(String desc){
		if(desc == null){
			return ;
		}
		tv_summary.setText(desc);
	}
	
	public void initItem(int iconResId,int titleResId){
		if(iconResId != -1){
			iconView.setImageResource(iconResId);
		}
		
		if(titleResId != -1){
			titleView.setText(titleResId);
		}
	}
	
	public void setIcon(int iconResId){
		if(iconResId != -1){
			iconView.setImageResource(iconResId);
		}
	}
	
	public void setTitle(int titleResId){
		if(titleResId != -1){
			titleView.setText(titleResId);
		}
	}
}
